<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>广告管理</title>
	<meta http-equiv="Access-Control-Allow-Origin" content="*">
	<meta name="decorator" content="default"/>
	<script type="text/javascript" src="${ctxStatic}/common/jquery-2.0.0.min.js"></script>

	<script type="text/javascript" src="${ctxStatic}/bower_components/moxie.js"></script>
	<script type="text/javascript" src="${ctxStatic}/bower_components/plupload.dev.js"></script>
	<%--<script type="text/javascript" src="/static/bower_components/plupload/js/plupload.full.min.js"></script>--%>
	<script type="text/javascript" src="${ctxStatic}/bower_components/qiniu.js"></script>
	<script type="text/javascript" src="${ctxStatic}/jquery-validation/1.11.0/jquery.validate.min.js"></script>
	<script type="text/javascript" src="${ctxStatic}/ckeditor/ckeditor.js"></script>
	<link href="${ctxStatic}/common/mycss.css" rel="stylesheet" type="css">
	<script type="text/javascript">
		$(document).ready(function() {
			$("#value").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
	<script>
		$(document).ready(function () {
			$(document).on("click", "A[name='deleteImg']", function () {
				$(this).parent().remove();
			});
			//$("#value").focus();
		});

	</script>
	<script>
		$(function () {
			var uploader = Qiniu.uploader({
				runtimes: 'html5,flash,html4',
				browse_button: 'pickfiles',
				container: 'container',
				drop_element: 'container',
				max_file_size: '1000mb',
				flash_swf_url: 'bower_components/plupload/js/Moxie.swf',
				dragdrop: true,
				chunk_size: '4mb',
				multi_selection: !(mOxie.Env.OS.toLowerCase() === "ios"),
				// uptoken_url: '/a/qiniu/upload/token',http://localhost:8080/a/qiniu/upload/token"
				uptoken_url: '/a/qiniu/upload/token',
				domain: "oframjnn6.bkt.clouddn.com",
				get_new_uptoken: false,
				auto_start: true,
				log_level: 5,
				unique_names: true,
				init: {
					'FilesAdded': function (up, files) {
						plupload.each(files, function (file) {
						});
					},
					'BeforeUpload': function (up, file) {
					},
					'UploadProgress': function (up, file) {
						console.log(up);
					},
					'UploadComplete': function () {
					},
					'FileUploaded': function (up, file, info) {
					},
					'Error': function (up, err, errTip) {

					}
				}
			});

			uploader.bind('FileUploaded', function (up, file, info) {

				console.log("resp_URL : " + JSON.parse(info.response).key);
				var _url = 'http://oframjnn6.bkt.clouddn.com/' + JSON.parse(info.response).key;
				var _html = '<li><img src="'+_url+'" ' +
						'url="'+_url+'" ' +
						'style="max-width:100px;max-height:100px;_height:100px;border:0;padding:3px;"> ' +
						'<input type="hidden" name="adImageUrl" value="'+_url+'"> ' +
						'&nbsp;&nbsp; ' +
						'<a href="javascript:void(0)" name="deleteImg">×</a> ' +
						'<input type="hidden" value="'+_url+'" class="input-text form-control"/></li>';
				console.log(_html);
				$("#nameImagePreview").html(_html);
			});

		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/advertise/">广告列表</a></li>
		<li class="active"><a href="${ctx}/sys/advertise/form?id=${advertise.id}">广告<shiro:hasPermission name="sys:advertise:edit">${not empty advertise.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:advertise:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tbAdvertise" action="${ctx}/sys/advertise/advertiseEdit" method="post" class="form-horizontal" enctype="multipart/form-data">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">标题:</label>
			<div class="controls">
				<form:input path="title" htmlEscape="false" maxlength="50" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">链接地址:</label>
			<div class="controls">
				<form:input path="adUrl" htmlEscape="false" maxlength="1000" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">描述:</label>
			<div class="controls">
				<form:input path="adDesc" htmlEscape="false" maxlength="1000" class="required"/>
			</div>
		</div>
		<%--<div class="control-group">
			<label class="control-label">广告图片:</label>
			<div class="controls">
				&lt;%&ndash;<form:hidden id="nameImage" path="adImageUrl" htmlEscape="false" maxlength="255" class="input-xlarge"/>
				<sys:ckfinder input="nameImage" type="images" uploadPath="/adImageUrl" selectMultiple="false" maxWidth="100" maxHeight="100"/>&ndash;%&gt;
			</div>
		</div>--%>
		<div class="control-group">
			<label id="container" class="control-label"><a class="btn btn-default btn-lg " id="pickfiles" href="#">
				<i class="glyphicon glyphicon-plus"></i>
				<span>选择图片</span>
			</a>:</label>
			<div class="controls">
				<ol id="nameImagePreview">
					<c:if test="${advertise.adImageUrl!=null}">
						<li><img src="${advertise.adImageUrl}"
								 url="${advertise.adImageUrl}"
								 style="max-width:100px;max-height:100px;_height:100px;border:0;padding:3px;">
							<input type="hidden" name="adImageUrl" value="${advertise.adImageUrl}">
							<a href="javascript:void(0)" name="deleteImg">删除</a>
							&nbsp;&nbsp;
						</li>
					</c:if>
				</ol>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否显示:</label>
			<div class="controls">
				<form:radiobuttons path="isActive" items="${fns:getDictList('show_hide')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required"/>
				<span class="help-inline">该广告否显示到微信中</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">排序:</label>
			<div class="controls">
				<form:input path="adSort" htmlEscape="false" maxlength="11" class="required digits"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:advertise:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>